// 社团成员关系模型
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = require('./User');
const Association = require('./Association');

const AssociationMember = sequelize.define('AssociationMember', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: User,
      key: 'id'
    },
    comment: '用户ID'
  },
  associationId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: Association,
      key: 'id'
    },
    comment: '社团ID'
  },
  role: {
    type: DataTypes.STRING(20),
    allowNull: false,
    defaultValue: 'member',
    comment: '角色 member:成员 president:社长 vice-president:副社长'
  },
  joinDate: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    comment: '加入日期'
  },
  status: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    comment: '状态 1:正常 2:申请中 3:已退出 4:已移除'
  }
}, {
  tableName: 'association_members',
  timestamps: true,
  charset: 'utf8mb4',
  collate: 'utf8mb4_unicode_ci'
});

// 关联关系
AssociationMember.belongsTo(User, { foreignKey: 'userId' });
AssociationMember.belongsTo(Association, { foreignKey: 'associationId' });

module.exports = AssociationMember;